
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4.2 Unity Shader和OpenGL Shader · 游戏引擎浅入浅出</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="captainchen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.3 顶点着色器.html" />
    
    
    <link rel="prev" href="4.1 着色器是什么.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">目录</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../前言.html">
            
                <a href="../前言.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../1. 游戏引擎框架介绍/1. 游戏引擎框架介绍.html">
            
                <a href="../1. 游戏引擎框架介绍/1. 游戏引擎框架介绍.html">
            
                    
                    1. 游戏引擎框架介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../1. 游戏引擎框架介绍/1.1 暗中观察unity.html">
            
                <a href="../1. 游戏引擎框架介绍/1.1 暗中观察unity.html">
            
                    
                    1.1 暗中观察unity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../1. 游戏引擎框架介绍/1.2 游戏引擎组成.html">
            
                <a href="../1. 游戏引擎框架介绍/1.2 游戏引擎组成.html">
            
                    
                    1.2 游戏引擎组成
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../2. Opengl开发环境搭建/2. Opengl开发环境搭建.html">
            
                <a href="../2. Opengl开发环境搭建/2. Opengl开发环境搭建.html">
            
                    
                    2. Opengl开发环境搭建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../2. Opengl开发环境搭建/2.1 Opengl到底是什么.html">
            
                <a href="../2. Opengl开发环境搭建/2.1 Opengl到底是什么.html">
            
                    
                    2.1 Opengl到底是什么
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../2. Opengl开发环境搭建/2.2 搭建Opengl开发环境.html">
            
                <a href="../2. Opengl开发环境搭建/2.2 搭建Opengl开发环境.html">
            
                    
                    2.2 搭建Opengl开发环境
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../3. 绘制简单图形/3. 绘制简单图形.html">
            
                <a href="../3. 绘制简单图形/3. 绘制简单图形.html">
            
                    
                    3. 绘制简单图形
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../3. 绘制简单图形/3.1 画个三角形.html">
            
                <a href="../3. 绘制简单图形/3.1 画个三角形.html">
            
                    
                    3.1 画个三角形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../3. 绘制简单图形/3.2 画个正方形.html">
            
                <a href="../3. 绘制简单图形/3.2 画个正方形.html">
            
                    
                    3.2 画个正方形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../3. 绘制简单图形/3.3 画个立方体.html">
            
                <a href="../3. 绘制简单图形/3.3 画个立方体.html">
            
                    
                    3.3 画个立方体
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="4. 着色器.html">
            
                <a href="4. 着色器.html">
            
                    
                    4. 着色器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="4.1 着色器是什么.html">
            
                <a href="4.1 着色器是什么.html">
            
                    
                    4.1 着色器是什么
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.5.2" data-path="4.2 Unity Shader和OpenGL Shader.html">
            
                <a href="4.2 Unity Shader和OpenGL Shader.html">
            
                    
                    4.2 Unity Shader和OpenGL Shader
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="4.3 顶点着色器.html">
            
                <a href="4.3 顶点着色器.html">
            
                    
                    4.3 顶点着色器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="4.4 片段着色器.html">
            
                <a href="4.4 片段着色器.html">
            
                    
                    4.4 片段着色器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../5. 绘制贴图/5. 绘制贴图.html">
            
                <a href="../5. 绘制贴图/5. 绘制贴图.html">
            
                    
                    5. 绘制贴图
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../5. 绘制贴图/5.1 颜色和贴图.html">
            
                <a href="../5. 绘制贴图/5.1 颜色和贴图.html">
            
                    
                    5.1 颜色和贴图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../5. 绘制贴图/5.2 贴图文件介绍.html">
            
                <a href="../5. 绘制贴图/5.2 贴图文件介绍.html">
            
                    
                    5.2 贴图文件介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../5. 绘制贴图/5.3 CPU与GPU的通信方式.html">
            
                <a href="../5. 绘制贴图/5.3 CPU与GPU的通信方式.html">
            
                    
                    5.3 CPU与GPU的通信方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../5. 绘制贴图/5.4 使用stb_image解析图片.html">
            
                <a href="../5. 绘制贴图/5.4 使用stb_image解析图片.html">
            
                    
                    5.4 使用stb_image解析图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../5. 绘制贴图/5.5 绘制带贴图的立方体盒子.html">
            
                <a href="../5. 绘制贴图/5.5 绘制带贴图的立方体盒子.html">
            
                    
                    5.5 绘制带贴图的立方体盒子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../5. 绘制贴图/5.6 压缩纹理.html">
            
                <a href="../5. 绘制贴图/5.6 压缩纹理.html">
            
                    
                    5.6 压缩纹理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.7" data-path="../5. 绘制贴图/5.7 图片压缩工具.html">
            
                <a href="../5. 绘制贴图/5.7 图片压缩工具.html">
            
                    
                    5.7 图片压缩工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.8" data-path="../5. 绘制贴图/5.8 使用压缩纹理.html">
            
                <a href="../5. 绘制贴图/5.8 使用压缩纹理.html">
            
                    
                    5.8 使用压缩纹理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../6. 索引与缓冲区对象/6. 缓冲区对象.html">
            
                <a href="../6. 索引与缓冲区对象/6. 缓冲区对象.html">
            
                    
                    6. 缓冲区对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../6. 索引与缓冲区对象/6.1 顶点索引.html">
            
                <a href="../6. 索引与缓冲区对象/6.1 顶点索引.html">
            
                    
                    6.1 顶点索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../6. 索引与缓冲区对象/6.2 缓冲区对象.html">
            
                <a href="../6. 索引与缓冲区对象/6.2 缓冲区对象.html">
            
                    
                    6.2 缓冲区对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../7. Mesh和材质/7. Mesh和材质.html">
            
                <a href="../7. Mesh和材质/7. Mesh和材质.html">
            
                    
                    7. Mesh和材质
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="../7. Mesh和材质/7.1 导出Mesh文件.html">
            
                <a href="../7. Mesh和材质/7.1 导出Mesh文件.html">
            
                    
                    7.1 导出Mesh文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="../7. Mesh和材质/7.2 使用Mesh文件.html">
            
                <a href="../7. Mesh和材质/7.2 使用Mesh文件.html">
            
                    
                    7.2 使用Mesh文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="../7. Mesh和材质/7.3 Shader文件创建与使用.html">
            
                <a href="../7. Mesh和材质/7.3 Shader文件创建与使用.html">
            
                    
                    7.3 Shader文件创建与使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >4.2 Unity Shader和OpenGL Shader</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <html><head></head><body><div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#42-unity-shader&#x548C;opengl-shader"><b></b>4.2 Unity Shader&#x548C;OpenGL Shader</a></li><ul><li><span class="title-icon "></span><a href="#1-unity-shader&#x7C7B;&#x578B;"><b></b>1. Unity Shader&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#2-unity-shader&#x4EE3;&#x7801;"><b></b>2. Unity Shader&#x4EE3;&#x7801;</a></li><li><span class="title-icon "></span><a href="#3unity-shader&#x8F6C;opengl-shader"><b></b>3.Unity Shader&#x8F6C;OpenGL Shader</a></li></ul></ul></ul></div><h2 id="42-unity-shader&#x548C;opengl-shader"><a name="42-unity-shader&#x548C;opengl-shader" class="anchor-navigation-ex-anchor" href="#42-unity-shader&#x548C;opengl-shader"><i class="fa fa-link" aria-hidden="true"></i></a>4.2 Unity Shader&#x548C;OpenGL Shader</h2>
<p>&#x4E0A;&#x4E00;&#x8282;&#x63D0;&#x5230;&#xFF0C;OpenGL Shader&#x662F;&#x914D;&#x5957;&#x51FA;&#x73B0;&#x7684;&#xFF0C; Vertex Shader(&#x9876;&#x70B9;&#x7740;&#x8272;&#x5668;)&#x3001;Fragment Shader(&#x7247;&#x6BB5;&#x7740;&#x8272;&#x5668;)&#xFF0C;&#x4E24;&#x8005;&#x7F3A;&#x4E00;&#x4E0D;&#x53EF;&#x3002;</p>
<p>&#x4F46;&#x662F;&#x6211;&#x7528;&#x4E86;20&#x5E74;Unity&#x90FD;&#x6CA1;&#x6709;&#x89C1;&#x8FC7;&#x7C7B;&#x4F3C;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x8FD9;&#x662F;&#x548B;&#x56DE;&#x4E8B;&#xFF0C;Unity&#x8DF3;&#x8FC7;OpenGL&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x4E86;&#x56FE;&#x5F62;&#x5E93;&#x5417;&#xFF1F;</p>
<h3 id="1-unity-shader&#x7C7B;&#x578B;"><a name="1-unity-shader&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#1-unity-shader&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. Unity Shader&#x7C7B;&#x578B;</h3>
<p>&#x6253;&#x5F00;Unity&#xFF0C;&#x65B0;&#x5EFA;Shader&#x3002;</p>
<p><a href="../../imgs/shader/unityshader_vs_openglshader/unity_shader_types.png" data-lightbox="4239ad7a-5d3c-47a1-89c5-735a6691a066" data-title=""><img src="../../imgs/shader/unityshader_vs_openglshader/unity_shader_types.png" alt=""></a></p>
<p>&#x5728;Unity&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;4&#x79CD;Shader&#x3002;</p>
<ol>
<li>Standard Surface Shader</li>
<li>Unlit Shader</li>
<li>Image Effect Shader</li>
<li>Compute Shader</li>
</ol>
<p>&#x8FD9;4&#x79CD;Shader&#xFF0C;&#x662F;&#x5BF9;&#x4E00;&#x5957;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#x7684;Vertex Shader&#x3001;Fragment Shader&#x7EC4;&#x5408;&#xFF0C;&#x53D6;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<p>&#x4EE5;C&#x8BED;&#x8A00;&#x4E3A;&#x4F8B;&#xFF0C;&#x6211;&#x4EEC;&#x7F16;&#x5199;&#x591A;&#x4E2A;C&#x8BED;&#x8A00;&#x4EE3;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x7F16;&#x8BD1;&#x51FA;&#x5404;&#x79CD;&#x7A0B;&#x5E8F;&#xFF0C;&#x5982;&#x6536;&#x94F6;&#x53F0;&#x7A0B;&#x5E8F;&#x3001;&#x804A;&#x5929;&#x7A0B;&#x5E8F;&#x3001;&#x6E38;&#x620F;&#x7A0B;&#x5E8F;&#xFF0C;&#x6BCF;&#x4E00;&#x79CD;&#x7A0B;&#x5E8F;&#x90FD;&#x9488;&#x5BF9;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x7528;&#x7F16;&#x5199;&#x7684;Vertex Shader&#x3001;Fragment Shader&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7F16;&#x8BD1;&#x5F97;&#x5230;&#x5404;&#x79CD;&#x7A0B;&#x5E8F;&#xFF0C;&#x5982;&#x65E0;&#x5149;&#x7167;&#x7684;GPU&#x7A0B;&#x5E8F;&#x3001;&#x6709;&#x5149;&#x7167;&#x7684;GPU&#x7A0B;&#x5E8F;&#x3001;&#x7279;&#x6548;&#x7A0B;&#x5E8F;&#xFF0C;&#x6BCF;&#x4E00;&#x79CD;&#x7A0B;&#x5E8F;&#x90FD;&#x9488;&#x5BF9;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#x3002;</p>
<p>Unity&#x4E2D;&#x53EF;&#x9009;&#x7684;4&#x79CD;Shader&#xFF0C;&#x6BCF;&#x4E00;&#x79CD;&#x90FD;&#x662F;&#x9488;&#x5BF9;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#xFF0C;&#x6BCF;&#x4E00;&#x79CD;&#x90FD;&#x662F;&#x7531;&#x4E0D;&#x540C;&#x7684;Vertex Shader&#x3001;Fragment Shader&#x7EC4;&#x6210;&#x3002;</p>
<h3 id="2-unity-shader&#x4EE3;&#x7801;"><a name="2-unity-shader&#x4EE3;&#x7801;" class="anchor-navigation-ex-anchor" href="#2-unity-shader&#x4EE3;&#x7801;"><i class="fa fa-link" aria-hidden="true"></i></a>2. Unity Shader&#x4EE3;&#x7801;</h3>
<p>&#x4E0A;&#x9762;&#x8BF4;&#xFF0C;Unity Shader&#x662F;&#x7531;Vertex Shader&#x3001;Fragment Shader&#x7EC4;&#x6210;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;Unity Shader&#x91CC;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x7531;Vertex Shader&#x3001;Fragment Shader&#x62FC;&#x8D77;&#x6765;&#x54AF;&#xFF1F;</p>
<p>&#x5728; <code>3.&#x7ED8;&#x5236;&#x7B80;&#x5355;&#x56FE;&#x5F62;</code> &#x8FD9;&#x4E00;&#x7AE0;&#x7684;&#x914D;&#x5957;&#x9879;&#x76EE;&#x91CC;&#xFF0C;<code>ShaderSource.h</code> &#x5C31;&#x662F;&#x7531; Vertex Shader &#x548C; Fragment Shader &#x62FC;&#x8D77;&#x6765;&#x7684;&#xFF0C;&#x90A3;Unity Shader&#x4E5F;&#x662F;&#x5982;&#x6B64;&#x5417;&#xFF1F;</p>
<p>&#x521B;&#x5EFA;&#x4E00;&#x4E2A; <code>Standard Surface Shader</code>&#xFF0C;&#x89C2;&#x5BDF;&#x4EE3;&#x7801;&#xFF0C;&#x53D1;&#x73B0;&#x7ED3;&#x6784;&#x5B8C;&#x5168;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x8FDE; &#x5165;&#x53E3; <code>main</code> &#x51FD;&#x6570;&#x90FD;&#x6CA1;&#x6709;!</p>
<pre><code class="lang-cg">Shader &quot;Custom/NewSurfaceShader&quot; {
    Properties {
        _Color (&quot;Color&quot;, Color) = (1,1,1,1)
        _MainTex (&quot;Albedo (RGB)&quot;, 2D) = &quot;white&quot; {}
        _Glossiness (&quot;Smoothness&quot;, Range(0,1)) = 0.5
        _Metallic (&quot;Metallic&quot;, Range(0,1)) = 0.0
    }
    SubShader {
        Tags { &quot;RenderType&quot;=&quot;Opaque&quot; }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check &apos;Enable Instancing&apos; on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_CBUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_CBUFFER_END

        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack &quot;Diffuse&quot;
}
</code></pre>
<p>&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#xFF0C;&#x6211;&#x4EEC;&#x5728;Unity&#x4E2D;&#x5199;&#x7684;Shader&#x4EE3;&#x7801;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x6807;&#x51C6;&#x7684;OpenGL Shader&#xFF0C;&#x800C;&#x662F;NVIDIA&#x5F00;&#x53D1;&#x7684;Cg&#x8BED;&#x8A00;&#x3002;</p>
<p>Cg&#x8BED;&#x8A00;&#x53EF;&#x4EE5;&#x7531;&#x5DE5;&#x5177;&#xFF0C;&#x8F6C;&#x6362;&#x6210;OpenGL Shader&#xFF0C;&#x6216;&#x8005;DX Shader&#xFF0C;&#x6BD5;&#x7ADF;Unity&#x662F;&#x8DE8;&#x5E73;&#x53F0;&#x5F15;&#x64CE;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;Cg&#x8BED;&#x8A00;&#xFF0C;&#x90A3;&#x6BCF;&#x4E00;&#x79CD;&#x529F;&#x80FD;&#x7684;Shader&#x65E2;&#x8981;&#x5199;OpenGL&#x7684;&#xFF0C;&#x53C8;&#x8981;&#x5199;DX&#x7684;&#xFF0C;&#x8981;&#x7D2F;&#x6B7B;&#x7A0B;&#x5E8F;&#x5458;&#x4E86;&#x3002;</p>
<h3 id="3unity-shader&#x8F6C;opengl-shader"><a name="3unity-shader&#x8F6C;opengl-shader" class="anchor-navigation-ex-anchor" href="#3unity-shader&#x8F6C;opengl-shader"><i class="fa fa-link" aria-hidden="true"></i></a>3.Unity Shader&#x8F6C;OpenGL Shader</h3>
<p>Unity&#x4E2D;&#x9009;&#x4E2D;&#x521B;&#x5EFA;&#x7684;Shader&#xFF0C;&#x5728;Inspector&#x91CC;&#xFF0C;&#x6253;&#x5F00;Shader&#x7F16;&#x8BD1;&#x5E73;&#x53F0;&#x8BBE;&#x7F6E;&#xFF0C;&#x4FEE;&#x6539;&#x4E3A; <code>All platforms</code>&#x3002;
<a href="../../imgs/shader/unityshader_vs_openglshader/unity_compile_cg_to_opengl_shader.png" data-lightbox="a84a2b52-8f30-4f08-8d76-2e640fad50d5" data-title=""><img src="../../imgs/shader/unityshader_vs_openglshader/unity_compile_cg_to_opengl_shader.png" alt=""></a></p>
<p>&#x70B9;&#x51FB;<code>Compile and show code</code> &#x5C06;Unity Cg Shader&#x6587;&#x4EF6;&#x8F6C;&#x4E3A;OpenGL Shader&#x3002;</p>
<p>&#x8F6C;&#x6362;&#x5B8C;&#x6210;&#x540E;&#x81EA;&#x52A8;&#x6253;&#x5F00;&#xFF0C;&#x641C;&#x7D22; <code>glcore</code>&#xFF0C;&#x5B9A;&#x4F4D;&#x5230;&#x8F6C;&#x6362;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<p><a href="../../imgs/shader/unityshader_vs_openglshader/unity_compile_cg_to_opengl_shader_vertex_shader.png" data-lightbox="1265308b-c685-4499-aca5-72c931e5c2d8" data-title=""><img src="../../imgs/shader/unityshader_vs_openglshader/unity_compile_cg_to_opengl_shader_vertex_shader.png" alt=""></a></p>
<p>&#x8FD9;&#x5C31;&#x662F;&#x8F6C;&#x6362;&#x51FA;&#x6765;&#x7684;Vertex Shader&#x4EE3;&#x7801;&#xFF0C;&#x770B;&#x5230;&#x5165;&#x53E3; <code>main</code> &#x51FD;&#x6570;&#x4E86;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; captainchen all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">File Modify: 
2021-03-26 22:25:55
</span></footer></body></html>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="4.1 着色器是什么.html" class="navigation navigation-prev " aria-label="Previous page: 4.1 着色器是什么">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.3 顶点着色器.html" class="navigation navigation-next " aria-label="Next page: 4.3 顶点着色器">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4.2 Unity Shader和OpenGL Shader","level":"2.5.2","depth":2,"next":{"title":"4.3 顶点着色器","level":"2.5.3","depth":2,"path":"pages/4. 着色器/4.3 顶点着色器.md","ref":"pages/4. 着色器/4.3 顶点着色器.md","articles":[]},"previous":{"title":"4.1 着色器是什么","level":"2.5.1","depth":2,"path":"pages/4. 着色器/4.1 着色器是什么.md","ref":"pages/4. 着色器/4.1 着色器是什么.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","tbfed-pagefooter","splitter","lightbox","anchor-navigation-ex","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy captainchen","modify_format":"YYYY-MM-DD HH:mm:ss"},"livereload":{},"splitter":{},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"lightbox":{"jquery":true,"sameUuid":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"captainchen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"游戏引擎浅入浅出","gitbook":"*"},"file":{"path":"pages/4. 着色器/4.2 Unity Shader和OpenGL Shader.md","mtime":"2021-03-26T14:25:55.692Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-30T15:25:09.576Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

